-- lover
-- created by panyl
-- 恋人

return {
    apply = function(cardId)
        local args = TarotM.query(cardId, "args") or {};
        local bonus = table.deepcopy(args["bonus"]);
        local randomBonus = args["random_bonus"]
        if type(bonus) == 'table' and #bonus > 0 then
            if type(bonus[1]) == 'number' then
                -- 单个奖励
                local arr;
                if type(bonus[2]) == 'string' then
                    -- 千分比回复的处理
                    arr = string.explode(bonus[2], "_");
                end

                if bonus[1] == 2 and  #arr == 2 and "per" == arr[1] then
                    local force = bonus[3];
                    local maxAttrib = "max_" .. arr[2];
                    local attribName = "limit_" .. arr[2];
                    -- 计算回复量，最大属性（HP or MP）的千分比
                    local max = ME.user:queryAttrib(maxAttrib);
                    local num = math.modf(max * force / 1000);

                    if num > 0 then
                        BonusM.doBonus({ 2, attribName, num, }, "tarot_bonus");
                    end
                else
                    BonusM.doBonus(bonus, "tarot_bonus");
                end
            else
                -- 多个奖励
                local bonusList = bonus;
                for _, bonus in pairs(bonusList) do
                    -- 单个奖励
                    local arr;
                    if type(bonus[2]) == 'string' then
                        -- 千分比回复的处理
                        arr = string.explode(bonus[2], "_");
                    end
                    if bonus[1] == 2 and  #arr == 2 and "per" == arr[1] then
                        local force = bonus[3];
                        local maxAttrib = "max_" .. arr[2];
                        local attribName = "limit_" .. arr[2];
                        -- 计算回复量，最大属性（HP or MP）的千分比
                        local max = ME.user:queryAttrib(maxAttrib);
                        local num = math.modf(max * force / 1000);

                        if num > 0 then
                            BonusM.doBonus({ 2, attribName, num, }, "tarot_bonus");
                        end
                    else
                        BonusM.doBonus(bonus, "tarot_bonus");
                    end
                end
            end
        end

        if type(randomBonus) == 'table' and #randomBonus > 0 then
            -- 随机奖励
            local rand = DungeonM.getRandSeed("tarot_lover");
            bonus = randomBonus[ rand % #randomBonus + 1];

            BonusM.doBonus(bonus, "tarot_bonus");
        end
    end,
};
